import React, { Component } from 'react'
import { connect } from 'react-redux'
import axios from 'axios'
class App extends Component {
  componentDidMount () {
    this.props.getBannerList()
    this.props.getProList()
  }
  render() {
    const { bannerList, proList } = this.props
    return (
      <div>
        {
          bannerList.map(item => {
            return (
              <img key={ item.bannerid } src={item.img} alt=""/>
            )
          })
        }
        {
          proList.map(item => {
            return (
            <div key = { item.proid }> { item.proname }</div>
            )
          })
        }
      </div>
    )
  }
}

export default connect(
  (state) => {
    return {
      bannerList: state.bannerList,
      proList: state.proList
    }
  },
  (dispatch) => {
    return {
      getBannerList () {
        // http://121.89.205.189/apidoc/
        axios.get('http://121.89.205.189/api/banner/list').then(res => {
          dispatch({
            type: 'CHANGE_BANNER_LIST',
            payload: res.data.data
          })
        })
      },
      getProList () {
        axios.get('http://121.89.205.189/api/pro/list').then(res => {
          dispatch({
            type: 'CHANGE_PRO_LIST',
            payload: res.data.data
          })
        })
      }
    }
  }
)(App)